package com.css.fxfzdpzs.modules.qh.controller;

import com.css.fxfzdpzs.base.response.RestResponse;
import com.css.fxfzdpzs.modules.qh.entity.*;
import com.css.fxfzdpzs.modules.qh.service.QhService;
import com.css.fxfzdpzs.modules.qh.vo.ProjectDrillGeomVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 全国地震安全性评价项目和钻孔位置分布图
 */
@Slf4j
@RestController
@RequestMapping("/qh")
public class QhController {
    @Autowired
    private QhService qhService;


    //全国项目/钻孔总体数量
    @GetMapping("/getProjectDrillNum")
    public RestResponse getProjectDrillNum() {
        RestResponse restResponse = null;
        try {
            ProjectDrillNum num = qhService.getProjectDrillNum();
            restResponse = RestResponse.succeed(num);
        } catch (Exception e) {
            String errormessage = "查询全国项目/钻孔总体数量失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //各省（直辖市）项目/钻孔据统计
    @GetMapping("/getProvinceCount")
    public RestResponse getProvinceCount(@RequestParam String type) {
        RestResponse restResponse = null;
        try {
            List<ProvinceCount> list = qhService.getProvinceCount(type);
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询各省（直辖市）项目/钻孔据统计失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //全国项目/钻孔总体数据更新
    @GetMapping("/getProjectDrillRenew")
    public RestResponse getProjectDrillRenew() {
        RestResponse restResponse = null;
        try {
            List<ProjectDrillRenew> list = qhService.getProjectDrillRenew();
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询全国项目/钻孔总体数据更新失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //全国项目/钻孔年份数据更新
    @GetMapping("/getYearProjectDrillRenew")
    public RestResponse getYearProjectDrillRenew() {
        RestResponse restResponse = null;
        try {
            List<YearProjectDrillRenew> list = qhService.getYearProjectDrillRenew();
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询全国项目/钻孔年份数据更新失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //不同工程类别数据统计
    @GetMapping("/getWorkCategoryCount")
    public RestResponse getWorkCategoryCount() {
        RestResponse restResponse = null;
        try {
            List<WorkCategoryCount> list = qhService.getWorkCategoryCount();
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询不同工程类别数据统计失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //各个项目和钻孔的经纬度点
    @GetMapping("/getLonAndLat")
    public RestResponse getLonAndLat() {
        RestResponse restResponse = null;
        try {
            Map<String , List<ProjectDrillGeomVo>> map = qhService.getLonAndLat();
            restResponse = RestResponse.succeed(map);
        } catch (Exception e) {
            String errormessage = "查询各个项目和钻孔的经纬度点失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }
}
